// 引入了工厂函数
import { createApp } from 'vue'
import App from './App.vue'
// elementUI
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
// 路由
import router from './router'
// store
import store from './store'

// 引入滚动条
import PerfectScrollbar from 'vue3-perfect-scrollbar'
import 'vue3-perfect-scrollbar/dist/vue3-perfect-scrollbar.css'
//引入 Markdown 编辑、预览组件
import VueMarkdownEditor from '@kangc/v-md-editor';
import '@kangc/v-md-editor/lib/style/base-editor.css';
import vuepressTheme from '@kangc/v-md-editor/lib/theme/vuepress.js';
import '@kangc/v-md-editor/lib/theme/style/vuepress.css';
import githubTheme from '@kangc/v-md-editor/lib/theme/github.js';


import Prism from 'prismjs';

VueMarkdownEditor.use(vuepressTheme, {
    Prism,
});

import VMdPreview from '@kangc/v-md-editor/lib/preview';
import '@kangc/v-md-editor/lib/style/preview.css';

import '@kangc/v-md-editor/lib/theme/style/github.css';

// 引入高亮
import hljs from 'highlight.js';
VMdPreview.use(vuepressTheme, {
    Hljs: hljs,
});

import createKatexPlugin from '@kangc/v-md-editor/lib/plugins/katex/cdn';

VueMarkdownEditor.use(createKatexPlugin())

VMdPreview.use(createKatexPlugin())
const app = createApp(App)

app.use(ElementPlus)
app.use(router)
app.use(VueMarkdownEditor)
app.use(VMdPreview)
app.use(PerfectScrollbar)
app.use(store)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.mount('#app')

import { ElMessage } from 'element-plus'
app.config.globalProperties.$message = ElMessage;
app.use(function (req, res, next) {
    //Enabling CORS
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type ,Accept, x-client-key, x-client-token, x-client-secret, Authorization");
    next();
});
